home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
basic
/
x10cmd.bas
< prev
next >
Wrap
BASIC Source File
|
1992-05-12
|
3KB
|
109 lines
REM
REM X10 basic interface code by Matt Drury (for demo purposes, enhancement)
REM turns on, off, or dims one X10 module - any housecode or unit
REM
REM feel free to modify at will; distribution with these credits required,
REM as well as your own enhancement credits. Please send me a copy of it!
REM
REM Home-automation support coming via London BBS at 407/423-5226 (1:363/69)
REM Feel free to Mail me on CompuServe at [75300,1610] as well
REM
REM * assumes com1 (change open statement if needed)
REM * does not look for the status bit returned
REM
CLS
DEFSTR A-C: DEFINT D-Z
REM below statements for future expansion
DIM al(16, 16): REM location names (LivRoom, etc)
DIM an(16, 16): REM module names (Light, Toaster, etc)
gethouse:
PRINT "Enter the house code (A-P): "; : GOSUB getchar: ah = UCASE$(ai)
IF ah < "A" OR ah > "P" THEN GOTO gethouse
getunit:
INPUT "Enter the unit code (1-16)"; un
IF un < 1 OR un > 16 THEN GOTO getunit
getcommand:
PRINT "Enter [1]On, [2]Off, [3]Dim"; : GOSUB getchar: ac = ai
IF ac < "1" OR ac > "3" THEN GOTO getcommand
getperc:
IF ac = "3" THEN INPUT "Percentage of brightness"; perc: IF perc < 0 OR perc > 100 THEN GOTO getperc
PRINT
PRINT "Sending command, please wait."
OPEN "COM1:600,N,8,1,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" FOR RANDOM AS #1
sendsync:
FOR i = 1 TO 16
PRINT #1, CHR$(255); : REM bytes 1-16
NEXT i
sendDirectCommandID:
PRINT #1, CHR$(1); : REM byte 17
sendfunction:
x = 0: REM will be byte 18 (level/function)
computelevel:
p1 = 100 - perc
IF p1 > 50 THEN x = x + 128: p1 = p1 - 50
IF p1 > 25 THEN x = x + 64: p1 = p1 - 25
IF p1 > 12 THEN x = x + 32: p1 = p1 - 12
IF p1 > 6 THEN x = x + 16: p1 = p1 - 6
computefunction:
IF ac = "1" THEN x = x + 2: REM on
IF ac = "2" THEN x = x + 3: REM off
IF ac = "3" THEN x = x + 5: REM dim
PRINT #1, CHR$(x); : REM byte 18 (level/function)
sendhousecode:
REM housecode database * 16 is below; A-P sequential
DATA 6,14,2,10,1,9,5,13,7,15,3,11,0,8,4,12
FOR i = 1 TO ASC(ah) - 64: READ n: NEXT i
y = n * 16: PRINT #1, CHR$(y); : REM byte 19 (housecode)
sendmodulebitmap:
IF un > 8 THEN z2 = 1: un = un - 9 ELSE z2 = 0: un = un - 1
z = 2 ^ (7 - un)
IF z2 = 1 THEN PRINT #1, CHR$(z); : PRINT #1, CHR$(0);
IF z2 = 0 THEN PRINT #1, CHR$(0); : PRINT #1, CHR$(z);
xsum = x + y + z
WHILE xsum > 255
xsum = xsum - 256
WEND
PRINT #1, CHR$(xsum); : REM byte 22 (Checksum)
RUN
getchar:
ai = INKEY$: IF ai = "" THEN GOTO getchar ELSE PRINT ai: RETURN